home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mastering Microsoft Visual Basic 5
/
Mastering Microsoft Visual Basic 5.ISO
/
labs
/
lab04
/
categories.frm
next >
Wrap
Text File
|
1997-01-24
|
8KB
|
306 lines
VERSION 5.00
Begin VB.Form Form1
Caption = "Categories"
ClientHeight = 3435
ClientLeft = 3450
ClientTop = 2325
ClientWidth = 5010
LinkTopic = "Form1"
ScaleHeight = 3435
ScaleWidth = 5010
Begin VB.CommandButton cmdClose
Caption = "C&lose"
Height = 375
Left = 3600
TabIndex = 10
Top = 3000
Width = 1335
End
Begin VB.CommandButton cmdFind
Caption = "&Find"
Height = 375
Left = 3600
TabIndex = 9
Top = 2520
Width = 1335
End
Begin VB.CommandButton cmdDelete
Caption = "&Delete"
Height = 375
Left = 3600
TabIndex = 8
Top = 2040
Width = 1335
End
Begin VB.CommandButton cmdCancel
Caption = "&Cancel"
Height = 375
Left = 3600
TabIndex = 7
Top = 1560
Width = 1335
End
Begin VB.CommandButton cmdEdit
Caption = "&Edit"
Height = 375
Left = 3600
TabIndex = 5
Top = 600
Width = 1335
End
Begin VB.CommandButton cmdSave
Caption = "&Save"
Height = 375
Left = 3600
TabIndex = 6
Top = 1080
Width = 1335
End
Begin VB.CommandButton cmdAdd
Caption = "&Add"
Height = 375
Left = 3600
TabIndex = 4
Top = 120
Width = 1335
End
Begin VB.CommandButton cmdNext
Caption = "Move Next >"
Height = 375
Left = 1920
TabIndex = 3
Top = 1680
Width = 1455
End
Begin VB.CommandButton cmdPrevious
Caption = "< Move Previous"
Height = 375
Left = 360
TabIndex = 2
Top = 1680
Width = 1455
End
Begin VB.TextBox txtCategoryName
Height = 285
Left = 1440
TabIndex = 0
Top = 600
Width = 2055
End
Begin VB.TextBox txtDescription
Height = 285
Left = 1440
TabIndex = 1
Top = 1080
Width = 2055
End
Begin VB.Label Label4
Caption = "&Description:"
Height = 255
Left = 120
TabIndex = 14
Top = 1200
Width = 975
End
Begin VB.Label Label3
Caption = "Category &Name:"
Height = 255
Left = 120
TabIndex = 13
Top = 720
Width = 1215
End
Begin VB.Label Label2
Caption = "Category &ID"
Height = 255
Left = 120
TabIndex = 12
Top = 240
Width = 975
End
Begin VB.Label lblCategoryID
BorderStyle = 1 'Fixed Single
Height = 285
Left = 1440
TabIndex = 11
Top = 120
Width = 2055
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim dbCurrent As Database
Dim recCategories As Recordset
Private Sub cmdAdd_Click()
' add a new record
recCategories.AddNew
lblCategoryID.Caption = recCategories.Fields("CategoryID")
txtCategoryName.Text = ""
txtDescription.Text = ""
ButtonEditAddMode
txtCategoryName.SetFocus
End Sub
Private Sub cmdCancel_Click()
recCategories.CancelUpdate
FillFields
ButtonNonEditAddMode
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub cmdDelete_Click()
recCategories.Delete
recCategories.MoveNext
If recCategories.EOF Then
recCategories.MoveLast
End If
FillFields
End Sub
Private Sub cmdEdit_Click()
recCategories.Edit
ButtonEditAddMode
End Sub
Private Sub cmdFind_Click()
Dim strSQL As String
Dim strAnswer As String
strAnswer = InputBox("Enter any portion of the Description", "Find Records")
strSQL = "Select * from categories where [Description] like " & _
"'*" & strAnswer & "*'"
' run the query
Set recCategories = dbCurrent.OpenRecordset(strSQL)
If recCategories.RecordCount = 0 Then
'no records found
MsgBox "No matching records found. Displaying all records."
Set recCategories = dbCurrent.OpenRecordset("Categories")
Else
'at least one record was found
recCategories.MoveFirst
FillFields
End If
End Sub
Private Sub cmdNext_Click()
recCategories.MoveNext
If recCategories.EOF Then
Beep
recCategories.MoveLast
Else
FillFields
End If
End Sub
Private Sub cmdPrevious_Click()
recCategories.MovePrevious
If recCategories.BOF Then
Beep
recCategories.MoveFirst
Else
FillFields
End If
End Sub
Private Sub cmdSave_Click()
' save the record
recCategories.Fields("CategoryName") = txtCategoryName.Text
recCategories.Fields("Description") = txtDescription.Text
recCategories.Update
recCategories.Bookmark = recCategories.LastModified
ButtonNonEditAddMode
End Sub
Private Sub Form_Load()
' open the Northwind Database
Set dbCurrent = OpenDatabase("..\..\Nwind.mdb")
' create a recordset based on the Categories table
Set recCategories = dbCurrent.OpenRecordset("Categories")
' move to the firecCategoriest record in the recordset
recCategories.MoveFirst
FillFields
ButtonNonEditAddMode
End Sub
Sub FillFields()
' populate the form with data from the recordset
lblCategoryID.Caption = recCategories.Fields("CategoryID")
txtCategoryName.Text = recCategories.Fields("CategoryName")
txtDescription.Text = recCategories.Fields("Description")
End Sub
Private Sub Form_Unload(Cancel As Integer)
' close the database
dbCurrent.Close
End Sub
Sub ButtonEditAddMode()
cmdSave.Enabled = True
cmdCancel.Enabled = True
cmdAdd.Enabled = False
cmdEdit.Enabled = False
cmdDelete.Enabled = False
cmdFind.Enabled = False
cmdClose.Enabled = False
cmdPrevious.Enabled = False
cmdNext.Enabled = False
txtCategoryName.Enabled = True
txtDescription.Enabled = True
End Sub
Sub ButtonNonEditAddMode()
cmdSave.Enabled = False
cmdCancel.Enabled = False
cmdAdd.Enabled = True
cmdEdit.Enabled = True
cmdDelete.Enabled = True
cmdFind.Enabled = True
cmdClose.Enabled = True
cmdPrevious.Enabled = True
cmdNext.Enabled = True
txtCategoryName.Enabled = False
txtDescription.Enabled = False
End Sub